import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Proporciona las rocas necesarias para agregar obstaculos al juego.
 * 
 * @author Asael Hernández García 
 * @version (a version number or a date)
 */
public class Roca extends Obstaculos
{
    /**
     * Act - do whatever the Roca wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    private SimpleTimer timer;
    private GreenfootImage imagen;
    private GreenfootSound roca;
    private int damage;
    
    public Roca()
    {
        timer = new SimpleTimer();
        timer.mark();
        resetPixels();
        imagen = new GreenfootImage("Roca.png");
        roca = new GreenfootSound("roca.wav");
        roca.setVolume(80);
        setImage(imagen);
        damage = 7;
    }
    
    public void act() 
    {
        mover();
        if(isTouching(Jugador.class)){
            roca.play();
            ((PistaAutomovil)getWorld()).addDamage(damage);
            damage = 0;
        }
        if(timer.millisElapsed() > 320) {
            if(getImage().getWidth() >= 10 && getImage().getHeight()>= 10)
                disminuyeTam(getImage().getWidth()-getPixels()-3, getImage().getHeight()-getPixels());  
            if(getY() <= getWorld().getHeight()/2 - getImage().getHeight()/2)    
                ((PistaAutomovil)getWorld()).removeObs(this);
            timer.mark();
            addPixels();
        }    
    }
}
